package com.base2.webshop.client.mvp;

import javax.inject.Singleton;

import com.base2.webshop.client.factories.ClientFactory;
import com.base2.webshop.client.factories.impl.ClientFactoryImpl;
import com.base2.webshop.shared.factory.WebShopRequestFactory;
import com.base2.webshop.shared.requests.ProductRequest;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.inject.client.AbstractGinModule;
import com.google.inject.Provides;
import com.gwtplatform.mvp.client.RootPresenter;
import com.gwtplatform.mvp.client.proxy.ParameterTokenFormatter;
import com.gwtplatform.mvp.client.proxy.PlaceManager;
import com.gwtplatform.mvp.client.proxy.TokenFormatter;

public class WebShopModule extends AbstractGinModule {

	@Override
	protected void configure() {
		bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
		bind(PlaceManager.class).to(WebShopPlaceManager.class).in(
				Singleton.class);
		bind(TokenFormatter.class).to(ParameterTokenFormatter.class).in(
				Singleton.class);
		bind(RootPresenter.class).asEagerSingleton();
		bind(ClientFactory.class).to(ClientFactoryImpl.class).in(
				Singleton.class);
		bind(WebShopRequestFactory.class).in(Singleton.class);
	}

	@Provides
	ProductRequest getProductRequest(WebShopRequestFactory requestFactory) {
		return requestFactory.getProductRequest();
	}
}
